/*
 * @(#) TagController.java 2018年3月5日 下午6:05:52
 *
 * Copyright 2018 CIMIP, Inc. All rights reserved.
 * H-VISIONS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */package cn.hc.share.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hc.share.entity.Tag;
import cn.hc.share.service.CommentSaveException;
import cn.hc.share.service.TagSaveException;
import cn.hc.share.service.TagService;
import cn.hc.share.util.JsonResult;

@Controller
 @RequestMapping("/tag")
public class TagController extends AbstractController
{

	@Resource
	private TagService tagService;

	@RequestMapping("/saveTag.do")
	@ResponseBody
	public Object saveTag(String tagNames,String builder)
	{
		System.out.println("tagName:"+tagNames+";userId:"+builder);
		String result = tagService.addNewTag(tagNames,builder);
		Object obj=result;
		return new JsonResult(obj);

	}

	@RequestMapping("/getTags.do")
	@ResponseBody
	public Object getTags(String userId)
	{
		List<Tag> tags = tagService.getTagsByUserId(userId);
		return new JsonResult(tags);
		
	}
	@RequestMapping("/updateTag.do")
	@ResponseBody
	public Object updateTag(String tagId,String tagNewName,String type)
	{
		
		System.out.println("2:"+tagId+";3:"+tagNewName+";4:"+type);
		
		int num = tagService.updateTag(tagId,tagNewName,type);
		Object obj=num;
		return new JsonResult(obj);
	}
	
	@ExceptionHandler(TagSaveException.class)
	@ResponseBody
	public JsonResult handleTagSave(TagSaveException e)
	{
		e.printStackTrace();
		return new JsonResult(2, e);
	}
	
}











